package com.example.springbootshiro.controller;


import com.example.springbootshiro.dao.BuildProductMapper;
import com.example.springbootshiro.entity.BuildProduct;
import com.example.springbootshiro.entity.JsonResult;
import com.example.springbootshiro.service.BuildProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/build")
public class BuildProductController {

    @Autowired
    private BuildProductService buildProductService;

    @RequestMapping("/listData")
    @ResponseBody
    public JsonResult list(String param1, String param2, String param3){
        JsonResult jsonResult = new JsonResult();
        List<BuildProduct> buildProducts = buildProductService.selectAll(param1, param2, param3);
        jsonResult.setMsg("ok");
        jsonResult.setData(buildProducts);
        jsonResult.setMsg("ok");
        return jsonResult;
    }

    @RequestMapping("/add")
    @ResponseBody
    public JsonResult add(@RequestBody BuildProduct buildProduct){
        JsonResult jsonResult = new JsonResult();
        buildProductService.add(buildProduct);
        jsonResult.setSuccess(true);
        jsonResult.setMsg("ko");
        return jsonResult;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(@RequestBody BuildProduct buildProduct){
        JsonResult jsonResult = new JsonResult();
        buildProductService.delete(buildProduct);
        jsonResult.setSuccess(true);
        jsonResult.setMsg("ko");
        return jsonResult;
    }


    @RequestMapping("/update")
    @ResponseBody
    public JsonResult update(@RequestBody BuildProduct buildProduct){
        JsonResult jsonResult = new JsonResult();
        buildProductService.update(buildProduct);
        jsonResult.setSuccess(true);
        jsonResult.setMsg("ko");
        return jsonResult;
    }


    @RequestMapping("/product")
    public String insert(){
        return "/product/product-add";
    }

    @RequestMapping("/home")
    public String list(){
        return "/product/product-home";
    }



    @RequestMapping("/product/info")
    public String info(){
        return "";
    }


}
